import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import numpy as np
import pandas as pd 
import pyodbc
import warnings
import pymysql
if __name__ == '__main__':
    from model_vn.utils import select_sql_mysql
    from model_vn.utils import select_sql_mysql_v1
    import util_log as util_log
else:
    from app.model_vn.utils import select_sql_mysql
    from app.model_vn.utils import select_sql_mysql_v1
    import app.model_vn.util_log as util_log
#from .utils import process_phone_number #获取手机号尾数,用来查询风控数据
warnings.filterwarnings("ignore")
pd.set_option('display.max_columns', 200) #让pandas显示所有列
pd.set_option('display.max_rows', 1000)    #显示所有行


def get_mysql_data(phone_sub, ApplyNO):
    """
    根据手机号后两位数字和订单号从MySQL数据库获取数据
    :param phone_sub:
    :param ApplyNO:
    :return:
    """
    sql_str = f"""
    select 
    AppName
    ,PackageName
    ,InstallationTime as FIRST_INSTALL_TIME
    ,CreateTime as LAST_UPDATE_TIME
    ,InsertTime as APP_CREATE_TIME
    ,ApplyNO as Phone 
    ,TIMESTAMPDIFF(Day,InstallationTime,InsertTime) as InstallInterval #app采集时间-首次安装时间
    ,TIMESTAMPDIFF(Day,CreateTime,InsertTime) as UpdateInterval #app采集时间-上次更新时间
    ,TIMESTAMPDIFF(Day,InstallationTime,CreateTime) as InstallUpdateInterval #上次更新时间-首次安装时间
    ,SUBSTRING(InstallationTime,1,10) as InstallDays
    ,SUBSTRING(CreateTime,1,10) as UpdateDays
    ,ThisApplyNO as ApplyNO
    from fk_applist_{phone_sub} 
    where ThisApplyNO = '{ApplyNO}'
    """
    #
    app_data = select_sql_mysql(sql_str)
    return app_data

def get_apptype():
    apptype_sql="""select  * from fk_apptype"""
    apptype_df=select_sql_mysql(apptype_sql)
    apptype_df.drop_duplicates(subset='AppName',inplace=True)
    return apptype_df

def get_free_app_features(phone_sub, ApplyNO):
    """
    根据手机号后两位和订单号获取数据并计算APP特征集
    :param phone_sub:
    :param ApplyNO:
    :return:
    """
    app_df = get_mysql_data(phone_sub, ApplyNO)
    apptype_df = get_apptype()
    return calculateFreeAppFeatures(app_df, apptype_df)

def get_format_data(df):
    """
    对获取的APP数据做格式化操作
    :param df:
    :return:
    """
    try:
        df_data_info = df
        if df_data_info.empty:
            return pd.DataFrame()
        # 数据格式化/清洗逻辑
        return df_data_info
    except Exception as e:
        util_log.get_logger().error(e)
        return pd.DataFrame()

def calculateFreeAppFeatures(app_df, apptype_df):
    try:
        df = get_format_data(app_df)
        if df.empty:
            return {}
        df_tmp = df.copy()

        ###################   衍生app类变量的计算逻辑   #########################
        
        app_df=pd.merge(app_df,apptype_df[['AppName','AppType']],how='left',on='AppName')
        df_sample_type6=app_df[app_df['AppType']==6]
        df_main=df_sample_type6.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_cnt_ty6"})
        
        # Ins_cnt_ty5_all_rat  安装的贷款类的app占总安装的app占比  衍生逻辑
        #先计算总的app个数
        df_all=app_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_app_all_cnt"})
        df_main=df_main.merge(df_all,how='left',on='ApplyNO')
        #计算种类为5的app数量
        df_sample_type5=app_df[app_df['AppType']==5]
        df_count_type5=df_sample_type5.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_cnt_ty5"})
        df_main=df_main.merge(df_count_type5,how='left',on='ApplyNO')
        df_main['Ins_cnt_ty5_all_rat']=df_main["Ins_cnt_ty5"]/df_main["Ins_app_all_cnt"]
        # 排查正确
        
        # Ins_cnt_ty6_all_rat  安装生活类的app占总安装的app占比  衍生逻辑 
        #已计算出种类为6的app个数和总的app个数，相除即可
        df_main['Ins_cnt_ty6_all_rat']=df_main['Ins_cnt_ty6']/df_main['Ins_app_all_cnt']
        
        # Ins_1ty_90d_cnt_all_rat   近90天安装的社交类的app占总安装的app占比 衍生逻辑 
        #选取InstallInterval <=90天且 AppType为1的app
        Ins_1ty_90d_df=app_df[(app_df['InstallInterval']<=90) & (app_df['AppType']==1)]
        Ins_1ty_90d_cnt=Ins_1ty_90d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_1ty_90d_cnt"})
        #用ApplyNO进行匹配
        df_main=df_main.merge(Ins_1ty_90d_cnt,how='left',on='ApplyNO')
        df_main['Ins_1ty_90d_cnt_all_rat']=df_main['Ins_1ty_90d_cnt']/df_main['Ins_app_all_cnt']
        
        # Ins_4ty_30d_cnt_all_rat  近30天安装的银行类的app占总安装的app占比 衍生逻辑 
        #选取InstallInterval <=30天且 AppType为4的app
        Ins_4ty_30d_df=app_df[(app_df['InstallInterval']<=30) & (app_df['AppType']==4)]
        #计算InstallInterval <=30天且 AppType为4的app个数
        Ins_4ty_30d_cnt=Ins_4ty_30d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_4ty_30d_cnt"})
        #用ApplyNO进行匹配
        df_main=df_main.merge(Ins_4ty_30d_cnt,how='left',on='ApplyNO')
        df_main['Ins_4ty_30d_cnt_all_rat']=df_main['Ins_4ty_30d_cnt']/df_main['Ins_app_all_cnt']
        
        # Ins_4ty_90d_cnt_all_rat  近90天安装的银行类的app占总安装的app占比 衍生逻辑 
        #选取InstallInterval <=90天且 AppType为4的app
        Ins_4ty_90d_df=app_df[(app_df['InstallInterval']<=90) & (app_df['AppType']==4)]
        #计算InstallInterval <=90天且 AppType为4的app个数
        Ins_4ty_90d_cnt=Ins_4ty_90d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_4ty_90d_cnt"})
        df_main=df_main.merge(Ins_4ty_90d_cnt,how='left',on='ApplyNO')
        df_main['Ins_4ty_90d_cnt_all_rat']=df_main['Ins_4ty_90d_cnt']/df_main['Ins_app_all_cnt']
        
        # Ins_6ty_90d_cnt_all_rat  近90天安装的生活类的app占总安装的app占比 衍生逻辑 
        #选取InstallInterval <=90天且 AppType为6的app
        Ins_6ty_90d_df=app_df[(app_df['InstallInterval']<=90) & (app_df['AppType']==6)]
        #计算InstallInterval <=90天且 AppType为4的app个数
        Ins_6ty_90d_cnt=Ins_6ty_90d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_6ty_90d_cnt"})
        #用ApplyNO进行匹配
        df_main=df_main.merge(Ins_6ty_90d_cnt,how='left',on='ApplyNO')
        #求占比
        df_main['Ins_6ty_90d_cnt_all_rat']=df_main['Ins_6ty_90d_cnt']/df_main['Ins_app_all_cnt']

        # Ins_5ty_1d_cnt_by_Ins_5ty_45d_cnt 近1天安装的贷款类app占近45天安装的贷款类app占比 
        #Ins_5ty_1d_cnt_by_Ins_5ty_60d_cnt  近1天安装的贷款类app占近60天安装的贷款类app占比
        #Ins_5ty_1d_cnt_by_Ins_5ty_90d_cnt  近1天安装的贷款类app占近90天安装的贷款类app占比 衍生逻辑
        #先求近1天安装的贷款类app数量，选取InstallInterval <=1天且 AppType为5的app
        Ins_5ty_1d_df=app_df[(app_df['InstallInterval']<=1) & (app_df['AppType']==5)]
        #近45天安装的贷款类app数量
        Ins_5ty_45d_df=app_df[(app_df['InstallInterval']<=45) & (app_df['AppType']==5)]
        #近60天安装的贷款类app数量
        Ins_5ty_60d_df=app_df[(app_df['InstallInterval']<=60) & (app_df['AppType']==5)]
        #近90天安装的贷款类app数量
        Ins_5ty_90d_df=app_df[(app_df['InstallInterval']<=90) & (app_df['AppType']==5)]
        #分别求个数
        Ins_5ty_1d_cnt=Ins_5ty_1d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_1d_cnt"})
        Ins_5ty_45d_cnt=Ins_5ty_45d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_45d_cnt"})
        Ins_5ty_60d_cnt=Ins_5ty_60d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_60d_cnt"})
        Ins_5ty_90d_cnt=Ins_5ty_90d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_90d_cnt"})
        #用ApplyNO进行匹配
        df_main=df_main.merge(Ins_5ty_1d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Ins_5ty_45d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Ins_5ty_60d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Ins_5ty_90d_cnt,how='left',on='ApplyNO')
        df_main['Ins_5ty_1d_cnt_by_Ins_5ty_45d_cnt']=df_main['Ins_5ty_1d_cnt']/df_main['Ins_5ty_45d_cnt']
        df_main['Ins_5ty_1d_cnt_by_Ins_5ty_60d_cnt']=df_main['Ins_5ty_1d_cnt']/df_main['Ins_5ty_60d_cnt']
        df_main['Ins_5ty_1d_cnt_by_Ins_5ty_90d_cnt']=df_main['Ins_5ty_1d_cnt']/df_main['Ins_5ty_90d_cnt']
        
        # Ins_5ty_3d_cnt_by_Ins_5ty_30d_cnt  近3天安装的贷款类app占近30天安装的贷款类app占比
        #Ins_5ty_3d_cnt_by_Ins_5ty_90d_cnt  近3天安装的贷款类app占近90天安装的贷款类app占比 衍生逻辑
        Ins_5ty_3d_df=app_df[(app_df['InstallInterval']<=3) & (app_df['AppType']==5)]
        Ins_5ty_30d_df=app_df[(app_df['InstallInterval']<=30) & (app_df['AppType']==5)]
        Ins_5ty_3d_cnt=Ins_5ty_3d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_3d_cnt"})
        Ins_5ty_30d_cnt=Ins_5ty_30d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_30d_cnt"})
        df_main=df_main.merge(Ins_5ty_3d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Ins_5ty_30d_cnt,how='left',on='ApplyNO')
        df_main['Ins_5ty_3d_cnt_by_Ins_5ty_30d_cnt']=df_main['Ins_5ty_3d_cnt']/df_main['Ins_5ty_30d_cnt']
        df_main['Ins_5ty_3d_cnt_by_Ins_5ty_90d_cnt']=df_main['Ins_5ty_3d_cnt']/df_main['Ins_5ty_90d_cnt']
        #Ins_5ty_14d_cnt_by_Ins_5ty_30d_cnt
        #Ins_5ty_14d_cnt_by_Ins_5ty_45d_cnt  
        #Ins_5ty_30d_cnt_by_Ins_5ty_90d_cnt 衍生逻辑
        Ins_5ty_14d_df=app_df[(app_df['InstallInterval']<=14) & (app_df['AppType']==5)]
        Ins_5ty_14d_cnt=Ins_5ty_14d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_14d_cnt"})
        df_main=df_main.merge(Ins_5ty_14d_cnt,how='left',on='ApplyNO')
        df_main['Ins_5ty_14d_cnt_by_Ins_5ty_30d_cnt']=df_main['Ins_5ty_14d_cnt']/df_main['Ins_5ty_30d_cnt']
        df_main['Ins_5ty_14d_cnt_by_Ins_5ty_45d_cnt']=df_main['Ins_5ty_14d_cnt']/df_main['Ins_5ty_45d_cnt']
        df_main['Ins_5ty_30d_cnt_by_Ins_5ty_90d_cnt']=df_main['Ins_5ty_30d_cnt']/df_main['Ins_5ty_90d_cnt']
        
        # Ins_88ty_7d_cnt_by_Ins_88ty_60d_cnt   近7天安装的金融类app占近60天安装的金融类app占比 衍生逻辑
        #求近7天种类为4和种类为5的变量的个数
        Ins_5ty_7d_df=app_df[(app_df['InstallInterval']<=7) & (app_df['AppType']==5)]
        Ins_5ty_7d_cnt=Ins_5ty_7d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_5ty_7d_cnt"})
        Ins_4ty_7d_df=app_df[(app_df['InstallInterval']<=7) & (app_df['AppType']==4)]
        Ins_4ty_7d_cnt=Ins_4ty_7d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_4ty_7d_cnt"})
        #求近60天种类为4变量的个数
        Ins_4ty_60d_df=app_df[(app_df['InstallInterval']<=60) & (app_df['AppType']==4)]
        Ins_4ty_60d_cnt=Ins_4ty_60d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Ins_4ty_60d_cnt"})
        df_main=df_main.merge(Ins_5ty_7d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Ins_4ty_7d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Ins_4ty_60d_cnt,how='left',on='ApplyNO')
        #统计
        df_loan=df_main[['ApplyNO','Ins_5ty_7d_cnt','Ins_4ty_7d_cnt','Ins_4ty_60d_cnt','Ins_5ty_60d_cnt']]
        df_loan=df_loan.fillna(0)  
        df_loan['Ins_88ty_7d_cnt']=df_loan['Ins_4ty_7d_cnt']+df_loan['Ins_5ty_7d_cnt']
        df_loan['Ins_88ty_60d_cnt']=df_loan['Ins_4ty_60d_cnt']+df_loan['Ins_5ty_60d_cnt']
        df_loan['Ins_88ty_7d_cnt_by_Ins_88ty_60d_cnt']=df_loan['Ins_88ty_7d_cnt']/df_loan['Ins_88ty_60d_cnt']
        df_main=df_main.merge(df_loan[['ApplyNO','Ins_88ty_7d_cnt_by_Ins_88ty_60d_cnt']],how='left',on='ApplyNO')

        # Upd_cnt_ty5_all_rat  更新贷款类的app占总安装的app占比 衍生逻辑
        #提出有更新过的app
        df_up_sample=app_df[app_df['InstallUpdateInterval']>0]
        Upd_cnt_ty5_df=df_up_sample[df_up_sample['AppType']==5]
        Upd_cnt_ty5_cnt=Upd_cnt_ty5_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Upd_cnt_ty5"})
        df_main=df_main.merge(Upd_cnt_ty5_cnt,how='left',on='ApplyNO')
        df_main['Upd_cnt_ty5_all_rat']=df_main['Upd_cnt_ty5']/df_main['Ins_app_all_cnt']
        #Upd_1ty_45d_cnt_all_rat
        #Upd_1ty_60d_cnt_all_rat
        #Upd_5ty_45d_cnt_all_rat
        #Upd_9ty_45d_cnt_all_rat 衍生逻辑
        #求1ty_45d，1ty_60d，5ty_45d，9ty_45d的app个数
        Upd_1ty_45d_df=df_up_sample[(df_up_sample['UpdateInterval']<=45) & (df_up_sample['AppType']==1)]
        Upd_1ty_45d_cnt=Upd_1ty_45d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Upd_1ty_45d_cnt"})
        Upd_1ty_60d_df=df_up_sample[(df_up_sample['UpdateInterval']<=60) & (df_up_sample['AppType']==1)]
        Upd_1ty_60d_cnt=Upd_1ty_60d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Upd_1ty_60d_cnt"})
        Upd_5ty_45d_df=df_up_sample[(df_up_sample['UpdateInterval']<=45) & (df_up_sample['AppType']==5)]
        Upd_5ty_45d_cnt=Upd_5ty_45d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Upd_5ty_45d_cnt"})
        Upd_9ty_45d_df=df_up_sample[(df_up_sample['UpdateInterval']<=45) & (df_up_sample['AppType']==9)]
        Upd_9ty_45d_cnt=Upd_9ty_45d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Upd_9ty_45d_cnt"})
        df_main=df_main.merge(Upd_1ty_45d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Upd_1ty_60d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Upd_5ty_45d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Upd_9ty_45d_cnt,how='left',on='ApplyNO')
        df_main['Upd_1ty_45d_cnt_all_rat']=df_main['Upd_1ty_45d_cnt']/df_main['Ins_app_all_cnt']
        df_main['Upd_1ty_60d_cnt_all_rat']=df_main['Upd_1ty_60d_cnt']/df_main['Ins_app_all_cnt']
        df_main['Upd_5ty_45d_cnt_all_rat']=df_main['Upd_5ty_45d_cnt']/df_main['Ins_app_all_cnt']
        df_main['Upd_9ty_45d_cnt_all_rat']=df_main['Upd_9ty_45d_cnt']/df_main['Ins_app_all_cnt']
        # Upd_9ty_60d_cnt_by_Upd_9ty_90d_cnt  近60天更新的工作类的app占近90天更新的工作类的app占比  衍生逻辑
        #求9ty_60d_，9ty_90的app 个数
        Upd_9ty_60d_df=df_up_sample[(df_up_sample['UpdateInterval']<=60)&(df_up_sample['AppType']==9)]
        Upd_9ty_60d_cnt=Upd_9ty_60d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Upd_9ty_60d_cnt"})
        Upd_9ty_90d_df=df_up_sample[(df_up_sample['UpdateInterval']<=90)&(df_up_sample['AppType']==9)]
        Upd_9ty_90d_cnt=Upd_9ty_90d_df.groupby('ApplyNO')['AppName'].count().reset_index().rename(columns={"AppName":"Upd_9ty_90d_cnt"})
        df_main=df_main.merge(Upd_9ty_60d_cnt,how='left',on='ApplyNO')
        df_main=df_main.merge(Upd_9ty_90d_cnt,how='left',on='ApplyNO')
        df_main['Upd_9ty_60d_cnt_by_Upd_9ty_90d_cnt']=df_main['Upd_9ty_60d_cnt']/df_main['Upd_9ty_90d_cnt']
        
        dict_main = df_main.to_dict(orient='records')
        dict_main = dict_main[0]
        
        return {
            'Ins_cnt_ty6': dict_main['Ins_cnt_ty6'],
            'Ins_cnt_ty5_all_rat': dict_main['Ins_cnt_ty5_all_rat'],
            'Ins_cnt_ty6_all_rat': dict_main['Ins_cnt_ty6_all_rat'],
            'Ins_1ty_90d_cnt_all_rat': dict_main['Ins_1ty_90d_cnt_all_rat'],
            'Ins_4ty_30d_cnt_all_rat': dict_main['Ins_4ty_30d_cnt_all_rat'],
            'Ins_4ty_90d_cnt_all_rat': dict_main['Ins_4ty_90d_cnt_all_rat'],
            'Ins_6ty_90d_cnt_all_rat': dict_main['Ins_6ty_90d_cnt_all_rat'],
            'Ins_5ty_1d_cnt_by_Ins_5ty_45d_cnt': dict_main['Ins_5ty_1d_cnt_by_Ins_5ty_45d_cnt'],
            'Ins_5ty_1d_cnt_by_Ins_5ty_60d_cnt': dict_main['Ins_5ty_1d_cnt_by_Ins_5ty_60d_cnt'],
            'Ins_5ty_1d_cnt_by_Ins_5ty_90d_cnt': dict_main['Ins_5ty_1d_cnt_by_Ins_5ty_90d_cnt'],
            'Ins_5ty_3d_cnt_by_Ins_5ty_30d_cnt': dict_main['Ins_5ty_3d_cnt_by_Ins_5ty_30d_cnt'],
            'Ins_5ty_3d_cnt_by_Ins_5ty_90d_cnt': dict_main['Ins_5ty_3d_cnt_by_Ins_5ty_90d_cnt'],
            'Ins_5ty_14d_cnt_by_Ins_5ty_30d_cnt': dict_main['Ins_5ty_14d_cnt_by_Ins_5ty_30d_cnt'],
            'Ins_5ty_14d_cnt_by_Ins_5ty_45d_cnt': dict_main['Ins_5ty_14d_cnt_by_Ins_5ty_45d_cnt'],
            'Ins_5ty_30d_cnt_by_Ins_5ty_90d_cnt': dict_main['Ins_5ty_30d_cnt_by_Ins_5ty_90d_cnt'],
            'Ins_88ty_7d_cnt_by_Ins_88ty_60d_cnt': dict_main['Ins_88ty_7d_cnt_by_Ins_88ty_60d_cnt'],
            'Upd_cnt_ty5_all_rat': dict_main['Upd_cnt_ty5_all_rat'],
            'Upd_1ty_45d_cnt_all_rat': dict_main['Upd_1ty_45d_cnt_all_rat'],
            'Upd_1ty_60d_cnt_all_rat': dict_main['Upd_1ty_60d_cnt_all_rat'],
            'Upd_5ty_45d_cnt_all_rat': dict_main['Upd_5ty_45d_cnt_all_rat'],
            'Upd_9ty_45d_cnt_all_rat': dict_main['Upd_9ty_45d_cnt_all_rat'],
            'Upd_9ty_60d_cnt_by_Upd_9ty_90d_cnt': dict_main['Upd_9ty_60d_cnt_by_Upd_9ty_90d_cnt'],
        }

        
    except Exception as e:
        util_log.get_logger().error(e)
        return {
            'Ins_cnt_ty6': None,
            'Ins_cnt_ty5_all_rat': None,
            'Ins_cnt_ty6_all_rat': None,
            'Ins_1ty_90d_cnt_all_rat': None,
            'Ins_4ty_30d_cnt_all_rat': None,
            'Ins_4ty_90d_cnt_all_rat': None,
            'Ins_6ty_90d_cnt_all_rat': None,
            'Ins_5ty_1d_cnt_by_Ins_5ty_45d_cnt': None,
            'Ins_5ty_1d_cnt_by_Ins_5ty_60d_cnt': None,
            'Ins_5ty_1d_cnt_by_Ins_5ty_90d_cnt': None,
            'Ins_5ty_3d_cnt_by_Ins_5ty_30d_cnt': None,
            'Ins_5ty_3d_cnt_by_Ins_5ty_90d_cnt': None,
            'Ins_5ty_14d_cnt_by_Ins_5ty_30d_cnt': None,
            'Ins_5ty_14d_cnt_by_Ins_5ty_45d_cnt': None,
            'Ins_5ty_30d_cnt_by_Ins_5ty_90d_cnt': None,
            'Ins_88ty_7d_cnt_by_Ins_88ty_60d_cnt': None,
            'Upd_cnt_ty5_all_rat': None,
            'Upd_1ty_45d_cnt_all_rat': None,
            'Upd_1ty_60d_cnt_all_rat': None,
            'Upd_5ty_45d_cnt_all_rat': None,
            'Upd_9ty_45d_cnt_all_rat': None,
            'Upd_9ty_60d_cnt_by_Upd_9ty_90d_cnt': None,
        }


if __name__ == '__main__':
    # 测试用例1
    phone_sub = 1
    ApplyNO = '1679732000463928'
    app_features1 = get_free_app_features(phone_sub, ApplyNO)
    print(app_features1)